package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.ClassRollCallService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/jurisdiction")
public class ClassRollCallController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ClassRollCallService service;

    /**
     * @描述 查学校所有班级人数(小程序教师端)
     * @创建人 zm
     * @创建时间 2020/5/15
     */
    @RequestMapping("/queryClassSize")
    public Result queryClassSize(RequestParameterWrapper request) {
        //学校id
        String schoolId = request.getParam("schoolId");
        //管理员
        String admin = request.getParam("admin");
        //教师id
        String teacherId = request.getParam("teacherId");
        logger.info("queryClassSize-->schoolId={},admin={},teacherId={}", schoolId, admin, teacherId);
        return service.queryClassSize(Integer.parseInt(schoolId), admin, teacherId);
    }

    /**
     * @描述 课堂点名节次查询(小程序教师端)
     * @创建人 zm
     * @创建时间 2020/5/15
     */
    @RequestMapping("/queryClassStanza")
    public Result queryClassStanza(RequestParameterWrapper request,
                                   @RequestParam(value = "classId") Integer classId,//班级id
                                   @RequestParam(value = "time", required = false) String time) {//查询的天数时间 格式“2020-10-10”
        //学校id
        String schoolId = request.getParam("schoolId");
        logger.info("queryClassStanza-->schoolId={},classId={},time={}", schoolId, classId, time);
        return service.queryClassStanza(Integer.parseInt(schoolId), classId, time);

    }

    /**
     * @描述 根据班级id查班级人数点名信息(小程序教师端)
     * @创建人 zm
     * @创建时间 2020/5/16
     */
    @RequestMapping("/queryClassStudent")
    public Result queryClassStudent(RequestParameterWrapper request,
                                    @RequestParam(value = "classId") Integer classId,//班级id
                                    @RequestParam(value = "time") String time,//节次时间
                                    @RequestParam(value = "id") Integer id,
                                    @RequestParam(value = "name", required = false) String name) {//节次id
        //学校id
        String schoolId = request.getParam("schoolId");
        logger.info("queryClassStudent-->schoolId={},classId={},time={},id={}", schoolId, classId, time, id);
        return service.queryClassStudent(Integer.parseInt(schoolId), classId, time, id, name);
    }

    /**
     * @描述 批量添加学生课堂点名信息(小程序教师端)
     * @创建人 zm
     * @创建时间 2020/5/16
     */
    @RequestMapping("/batchAddClassAttend")
    public Result batchAddClassAttend(RequestParameterWrapper request,
                                      @RequestParam(value = "list") String list,//学生课堂点名信息
                                      @RequestParam(value = "id") Integer id) {//节次id
        //教师id
        String teacherId = request.getParam("teacherId");
        logger.info("batchAddClassAttend-->teacherId={},list={},id={}", teacherId, list, id);
        return service.batchAddClassAttend(list, id, Integer.parseInt(teacherId));
    }

    /**
     * @描述 该学校该天所有节次, 学校统计(小程序教师端)
     * @创建人 zm
     * @创建时间 2020/5/18
     */
    @RequestMapping("/querySchoolStanza")
    public Result querySchoolStanza(RequestParameterWrapper request,
                                    @RequestParam(value = "time") String time) {//时间
        String schoolId = request.getParam("schoolId");
        logger.info("querySchoolStanza-->schoolId={},time={}", schoolId, time);
        return service.querySchoolStanza(Integer.parseInt(schoolId), time);
    }

    /**
     * @描述 根据日期/班级查某天课堂点名数据统计(小程序教师端)
     * @创建人 zm
     * @创建时间 2020/5/18
     */
    @RequestMapping("/queryClassStanzaList")
    public Result queryClassStanzaList(RequestParameterWrapper request,
                                       @RequestParam(value = "classId") Integer classId,//班级id
                                       @RequestParam(value = "time") String time) {//时间
        String schoolId = request.getParam("schoolId");
        logger.info("queryClassStanzaList-->schoolId={},time={},classId={}", schoolId, time, classId);
        return service.queryClassStanzaList(Integer.parseInt(schoolId), classId, time);
    }


    /**
     * @描述 按添加查询课堂点名统计(小程序教师端)
     * @创建人 zm
     * @创建时间 2020/5/18
     */
    @RequestMapping("/queryClassStanzaCount")
    public Result queryClassStanzaCount(RequestParameterWrapper request,
                                        @RequestParam(value = "id", required = false) Integer id,//节次id
                                        @RequestParam(value = "time") String time) {//时间
        String schoolId = request.getParam("schoolId");
        logger.info("queryClassStanzaCount-->schoolId={},time={},id={}", schoolId, time, id);
        return service.queryClassStanzaCount(Integer.parseInt(schoolId), id, time);
    }

    /*
     * 家长端  2020-5-19
     *
     * */

    /**
     * @描述 根据学生id查某天课堂点名信息(家长端)
     * @创建人 zm
     * @创建时间 2020/5/18
     */
    @RequestMapping("/queryStanzaStudentId")
    public Result queryStanzaStudentId(@RequestParam(value = "studentId") Integer studentId,//学生id
                                       @RequestParam(value = "time") String time) {//查询时间
        logger.info("queryStanzaStudentId-->studentId={},time={}", studentId, time);
        return service.queryStanzaStudentId(studentId, time);
    }


    /**
     * @描述 根据学生id查学生课堂点名统计(家长端)
     * @创建人 zm
     * @创建时间 2020/5/18
     */
    @RequestMapping("/queryStanzaStudentIdCount")
    public Result queryStanzaStudentIdCount(@RequestParam(value = "studentId") Integer studentId,//学生id
                                            @RequestParam(value = "type", defaultValue = "1") Integer type,//type 1 当天 2本周 3上周 4本月 5自定义时间
                                            @RequestParam(value = "startTime", required = false) String startTime,//开始时间
                                            @RequestParam(value = "endTime", required = false) String endTime) {//自定义 时间
        logger.info("queryStanzaStudentIdCount-->studentId={},startTime={},endTime={},type={}", studentId, startTime, endTime, type);
        return service.queryStanzaStudentIdCount(studentId, type, startTime, endTime);
    }


    /**
     * @描述 查询管理的班级
     * @创建人 zm
     * @创建时间 2020/5/28
     */
    @RequestMapping("/queryManageClassByTeacherId")
    public Result queryManageClassByTeacherId(RequestParameterWrapper request) {
        //学校id
        String schoolId = request.getParam("schoolId");
        //管理员
        String admin = request.getParam("admin");
        //教师id
        String teacherId = request.getParam("teacherId");

        return service.queryManageClassByTeacherId(teacherId, schoolId, admin);
    }

    /**
     * @描述 修改授课状态
     * @创建人 zm
     * @创建时间 2020/5/28
     */
    @RequestMapping("/updateManageClassId")
    public Result updateManageClassId(@RequestParam(value = "classId") Integer classId,
                                      @RequestParam(value = "state") Integer state) {
        return service.updateManageClassId(classId, state);
    }

}
